let path = require('path')
let { CleanWebpackPlugin } = require('clean-webpack-plugin')
let html = require('html-webpack-plugin')

let MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
let terser = require('terser-webpack-plugin')
let webpack = require('webpack')
/* 
  babel 的使用  主要是为了 吧JS转译成 大部分浏览器偶能支持的语法
  三个核心  babel-loader  @babel/core  @babel/preset-env


*/
module.exports = {
  entry: './src/index.js',
  output: {
    filename: "index.[fullhash:8].js",
    path: path.resolve(__dirname, 'app')
  },
  plugins: [
    new CleanWebpackPlugin(),
    new html({
      template: './public/index.html'
    }),
    new MiniCssExtractPlugin(),
    new webpack.ProvidePlugin({
      $: 'jquery',
      // 自定义的名字：'包的名字'
    }),
    new webpack.IgnorePlugin({
      resourceRegExp: /^\.\/locale$/,
      contextRegExp: /moment$/,
    })
  ],
  devtool: 'eval-cheap-module-source-map',
  module: {
    // noParse: /axios/, // 就是告诉wenpack 当解析axios 不去解析axios的依赖
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
        //  可以单独建立一个配置文件  .babelrc   babel.config.js
        exclude: /node_modules/
      }, {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      }
    ]
  },
  devServer: {
    // proxy before
  },
  optimization: {
    minimizer: [
      new CssMinimizerPlugin(),
      new terser()
    ]
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    },
    extensions: ['.vue', '.js', '.json']
  }
}